#!/bin/sh
# Update reports in Linux if required
# Run via the "runscript" tool which sets environment & cwd
PATH=.:/bin:/usr/local/bin:/usr/bin; export PATH

# Make sure no two reports run at the same time
# This is not 100% foolproof, but "good enough"
if [ -f update.LOCK ]; then
   echo "Update LOCKED" >&2
   exit 1
fi
echo "Update-reports running as $$" > update.LOCK
mv -f logs/lastmake.log.6 logs/lastmake.log.7
mv -f logs/lastmake.log.5 logs/lastmake.log.6
mv -f logs/lastmake.log.4 logs/lastmake.log.5
mv -f logs/lastmake.log.3 logs/lastmake.log.4
mv -f logs/lastmake.log.2 logs/lastmake.log.3
mv -f logs/lastmake.log.1 logs/lastmake.log.2
mv -f logs/lastmake.log.0 logs/lastmake.log.1
mv -f logs/lastmake.log logs/lastmake.log.0

date > logs/lastmake.log
# Make sure new files get created with group write
umask 2
echo -n "Umask is " >> logs/lastmake.log
umask >> logs/lastmake.log
echo "Path is $PATH" >> logs/lastmake.log
nice -10 make counts >> logs/lastmake.log 2>&1 || echo "Error in make counts"
date >> logs/lastmake.log
nice -10 make reports >> logs/lastmake.log 2>&1 || echo "Error in make reports"
date >> logs/lastmake.log
nice -10 make bycountry >> logs/lastmake.log 2>&1 || echo "Error in make bycountry"
date >> logs/lastmake.log
nice -10 make managing >> logs/lastmake.log 2>&1 || echo "Error in make managing"
date >> logs/lastmake.log
rm update.LOCK
